#include<stdio.h>
#include<pthread.h>
#include<unistd.h>
pthread_mutex_t mutex;
pthread_cond_t cond;
void* route1(void* arg)
{
  char* name=(char*)arg;
  while(1)
  {
    pthread_cond_wait(&cond,&mutex);
    printf("%s:开始任务\n",name);
  }
}
void* route3(void* arg)
{
  char* name=(char*)arg;
  while(1)
  {
    pthread_cond_wait(&cond,&mutex);
    printf("%s:开始任务\n",name);
  }
}
void* route2(void* arg)
{
   while(1)
   {
     pthread_cond_broadcast(&cond);
     printf("%s:开始去唤醒\n",(char*)arg);
     sleep(1);
   }
}

int main()
{
 pthread_t tid1,tid2,tid3;

 pthread_mutex_init(&mutex,NULL);
 pthread_cond_init(&cond,NULL);
 pthread_create(&tid1,NULL,route1,(void*)"thread2");
 pthread_create(&tid2,NULL,route3,(void*)"thread3");
 pthread_create(&tid2,NULL,route3,(void*)"thread4");
 pthread_create(&tid3,NULL,route2,(void*)"thread1");


 pthread_join(tid1,NULL);
 pthread_join(tid2,NULL);
 pthread_join(tid3,NULL);

 pthread_mutex_destroy(&mutex);
 pthread_cond_destroy(&cond);

  return 0;
}
